//创建外网IP
(function($){
	$(function(){
		var resizePage = (function () {
            $("body,.pop-page").height($(window).height());
            var ww = $(window).width(),
                wh = $("body").innerHeight(),
                popTopH = $(".pop-top").outerHeight(true),
                popFootH = $(".pop-foot").outerHeight(true),
                $wrap = $(".pop-wrap");

            $wrap.height(wh - popTopH - popFootH);
            return arguments.callee;
        })();

        $(window).resize(resizePage);
        //关闭弹出层
        $(".close-pop").on("click",function(e){
        	e.stopPropagation();
        	window.parent.$.popHide();
        })
        
      	//ip输入框
      	$("#ip").ipBox({
      		port : true,
      		portIn : true,
            titleText : "ip段",
            titleOut : true,
            ipValue : "",
            noPoint : true
      	});
      	//网关输入
      	$("#gateway").ipBox({
      		port : false,
            titleText : "网关",
            titleOut : true,
            ipValue : "",
            noPoint : true
      	})
      	//DNS输入
      	$(".dns").ipBox({
      		port : false,
            titleText : "DNS",
            titleOut : true,
            ipValue : "",
            noPoint : true
      	})
      	$(".add-dns").ipBox({
      		port : false,
            titleText : "",
            titleOut : true,
            ipValue : "",
            noPoint : true
      	})
      	//分配池输入
      	$(".start-pool").ipBox({
      		port : false,
            titleText : "分配池开始地址",
            titleOut : true,
            ipValue : "",
            noPoint : true
      	})
      	$(".end-pool").ipBox({
      		port : false,
            titleText : "分配池结束地址",
            titleOut : true,
            ipValue : "",
            noPoint : true
      	})
      	
      	//IP相关操作
      	$(".pop-wrap")
			//新增DNS      		
      		.on("click",".add-dns-btn",function(e){
      			e.stopPropagation();
      			var newDns = $('<div class="new-dns">'+
								'<div class="add-dns c-f"></div>'+
								'<a class="del-dns-btn del-ip ip_btn"><span class="del-ip-btn num_icon"></span></a>'+
								'</div>');
				$(newDns).appendTo($("#dnsPanel")).ipBox({
					port : false,
		            titleText : "",
		            titleOut : true,
		            ipValue : "",
		            noPoint : true
				});
				$(".pop-wrap").scrollTop($(".pop-wrap")[0].scrollHeight);
      		})
      		//删除新增的DNS
      		.on("click",".del-dns-btn",function(e){
      			e.stopPropagation();
      			$(this).closest(".new-dns").remove();
      		})
      		//新增分配池
      		.on("click",".add-pool-ip",function(e){
      			e.stopPropagation();
      			var newPool = $('<div class="all-pool c-f pos-re">'+
								'<div class="start-pool ip-pool"></div>'+
								'<div class="end-pool ip-pool c-f"></div>'+
								'<div class="add-pool">'+
								'<span class="pool-line"></span>'+
								'<a class="del-pool-ip ip_btn"><span class="del-ip-btn num_icon"></span></a>'+
								'</div></div>');
				$(newPool).appendTo($("#poolPanel"));
				$(newPool).find(".start-pool").ipBox({
		      		port : false,
		            titleText : "",
		            titleOut : true,
		            ipValue : "",
		            noPoint : true
		      	})
		      	$(newPool).find(".end-pool").ipBox({
		      		port : false,
		            titleText : "",
		            titleOut : true,
		            ipValue : "",
		            noPoint : true
		      	})
		      	$(".pop-wrap").scrollTop($(".pop-wrap")[0].scrollHeight);
      		})
      		//删除新增的分配池
      		.on("click",".del-pool-ip",function(e){
      			e.stopPropagation();
      			$(this).closest(".all-pool").remove();
      		})
      	
      	//内容区域添加滚动条
      	$(".pop-wrap").niceScroll({
      		cursorcolor:"#0099ff",
            autohidemode:false
      	})
       
	})
})(jQuery)
